package com.xmz.cacheaside.request;

import com.xmz.cacheaside.model.ProductInventory;
import com.xmz.cacheaside.service.ProductInventoryService;

public class ProductUpdateRequest implements Request{

    private ProductInventoryService productInventoryService;
    /**
     * 商品库存
     */
    private ProductInventory productInventory;


    public ProductUpdateRequest(ProductInventoryService productInventoryService,
                                ProductInventory productInventory) {
        this.productInventoryService = productInventoryService;
        this.productInventory = productInventory;
    }

    @Override
    public void process() {
        //先删除缓存
        productInventoryService.removeProductInventoryCache(productInventory);

        //再更新db
        productInventoryService.updateProductInventory(productInventory);


    }

    @Override
    public Integer getProductId() {
        return productInventory.getProductId();
    }
}
